package hunterxhunter.greedisland.events;

import java.awt.event.KeyEvent;
import framework.eea.StateBasedGame;
import framework.eea.event.Event;
import framework.eea.gui.JFrameGameContainer;
import framework.eea.interfaces.Action;

/**
 *
 * @author Markus Schr&ouml;der
 */
public class KeyPressedUseActionEvent extends Event {

    private Action[] actions;
    private int[] keyCodes;
    
    public KeyPressedUseActionEvent(int[] keyCodes, Action[] actions) {
        super("KeyActionEvent");
        this.actions = actions;
        this.keyCodes = keyCodes;
    }
    
    @Override
    protected boolean performAction(JFrameGameContainer gc, StateBasedGame sb, int delta) {
        if(sb.getKeyPressedQueue().isEmpty())
            return false;
        KeyEvent e = sb.getKeyPressedQueue().peek();
        for(int i = 0; i < keyCodes.length; i++) {
            if(e.getKeyCode() == keyCodes[i]) {
                actions[i].update(gc, sb, delta, this);
            }
        }
        return false;
    }

}
